# -*- coding:utf-8 -*-
"""
Author：Administrator
Date:2022年01月18日
"""
import requests
import json
import pandas as pd

print("============如果退出请输入0并按回车===========")

while True:
	输入 = input('请输入要翻译的内容:')
	if 输入 == '0':
		break
	else:
		网址 = 'https://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule'
		UA伪装 = {
			"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36"
		}
		响应对象 = requests.post(url=网址, headers=UA伪装).text
		data = {}
		data['i'] = 输入
		data['doctype'] = 'json'
		data['from'] = 'AUTO'
		data['to'] = 'AUTO'
		data['client'] = "fanyideskweb"
		响应数据 = requests.post(url=网址, headers=UA伪装, params=data).text
		字典 = json.loads(响应数据)
		结果 = 字典["translateResult"][0][0]['tgt']
		数据 = pd.DataFrame({'a': [输入], 'b': [结果]})
		数据.to_csv('./翻译结果.csv', index=False, header=0, mode='a', encoding='ANSI')
